// pages/register/register.js
const app =getApp({})
Page({

    /**
     * 页面的初始数据
     */
    data: {
        user:"",
        username:"",
        openid:"",
        userpassword:"",
        address:""
    },
    /* 跳转到注册页面 */
    NavToLogin(){
        wx.navigateTo({
            url: '/pages/login/login',
        })
    },
    /* 获取账号 */
    userInput(e){
        console.log(e.detail.value);
        this.setData({
            user:e.detail.value
        })
    },
    /* 获取密码 */
    pwdInput(e){
        console.log(e.detail.value);
        this.setData({
            userpassword:e.detail.value
        })
    },
    /* 获取姓名 */
    userNameInput(e){
        console.log(e.detail.value);
        this.setData({
            username:e.detail.value
        })
    },
    /* address */
    /* useraddress(e){
        console.log(e.detail.value);
        this.setData({
            address:e.detail.value
        })
    }, */
    /* 账号注册 */
    registerNow(){
        if(this.data.username.length==0 || this.data.userpassword.length==0 || this.data.user.length==0){
            wx.showToast({
              title: '信息填写完整',
              icon:"error"
            })
            return
        }
        this.register()
    },
    /* 注册 */
    register(){
        wx.showLoading({
            title:"注册中"
        })
        wx.request({
          url: app.globalData.baseUrl+'/mini/register',
          method:"POST",
          data:{
              name:this.data.username,
              user:this.data.user,
              password:this.data.userpassword
          },success:(res)=>{
            wx.hideLoading()
            console.log(res);
            if(res.data.status==200){
                wx.showToast({
                  title: '注册成功',
                })
                wx.navigateBack()
            }else{
                wx.showToast({
                  title: res.data.msg,
                  icon:"none"
                })
            }
          },fail:(res)=>{
            wx.hideLoading()
              wx.showToast({
                title: 'erro',
                icon:"error"
              })
          }
        })
    },
})